Skip to content

Add Hyperbolic Sainte-Marie Equations 1D#135

Open
MarcoArtiano wants to merge 18 commits intomainfrom
ma/hyperbolized_sainte_marie
Open

Add Hyperbolic Sainte-Marie Equations 1D#135
MarcoArtiano wants to merge 18 commits intomainfrom
ma/hyperbolized_sainte_marie

Conversation

@MarcoArtiano
Copy link
Copy Markdown
Contributor

@MarcoArtiano MarcoArtiano commented Mar 29, 2026

The entropy conserving and well-balanced scheme is derived in https://arxiv.org/abs/2603.18978.

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

JuliaFormatter

[JuliaFormatter] reported by reviewdog 🐶

f2_fluxdiff = alpha_1 * equations.gravity * h_avg * b_jump + alpha_2 * 2 * p_avg * b_jump
f2_pointwise = (1 - alpha_1) * equations.gravity * h_ll * b_jump + (1 - alpha_2) * 2 * p_ll * b_jump


[JuliaFormatter] reported by reviewdog 🐶

f4_fluxdiff = alpha_3 * equations.celerity^2 * h_avg * v_jump - 2 * alpha_2 * equations.celerity^2 * v_avg * b_jump
f4_pointwise = (1 - alpha_3) * equations.celerity^2 * h_ll * v_jump - 2 * (1 - alpha_2) * equations.celerity^2 * v_ll * b_jump


[JuliaFormatter] reported by reviewdog 🐶

f2,
f3,
f4,
zero(eltype(u_ll)))


[JuliaFormatter] reported by reviewdog 🐶

equations::HyperbolicSainteMarieEquations1D)


[JuliaFormatter] reported by reviewdog 🐶


[JuliaFormatter] reported by reviewdog 🐶

e = (h_v^2 + h_w^2) / (2 * h) + h_p^2 / (2 * equations.celerity^2 * h) + 0.5f0 * equations.gravity * h^2 + equations.gravity * h * b


[JuliaFormatter] reported by reviewdog 🐶

@inline function Trixi.lake_at_rest_error(u, equations::HyperbolicSainteMarieEquations1D)


[JuliaFormatter] reported by reviewdog 🐶

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.30%. Comparing base (a9ae27b) to head (1b9ceff).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #135      +/-   ##
==========================================
+ Coverage   99.28%   99.30%   +0.02%     
==========================================
  Files          96       98       +2     
  Lines        5146     5290     +144     
==========================================
+ Hits         5109     5253     +144     
  Misses         37       37              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MarcoArtiano MarcoArtiano marked this pull request as ready for review March 29, 2026 12:40
Copy link
Copy Markdown
Member

@ranocha ranocha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

Comment on lines +4 to +12
@doc raw"""
HyperbolicSainteMarieEquations1D(; bathymetry_type = bathymetry_mild_slope,
gravity,
eta0 = 0.0,
h0,
alpha = 3.0)

Hyperbolic approximation of the Sainte-Marie system
[`SainteMarieEquations1D`](@ref) in one spatial dimension
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the docstring so that it matches the code here and not DispersiveShallowWater.jl.

Comment on lines +69 to +76
function HyperbolicSainteMarieEquations1D(; gravity, H0 = zero(gravity),
b0 = one(gravity), alpha = 3,
threshold_limiter = nothing)
T = promote_type(typeof(gravity), typeof(H0), typeof(b0), typeof(alpha))
if threshold_limiter === nothing
threshold_limiter = 500 * eps(T)
end
celerity = alpha * sqrt(gravity * b0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not use b0 to determine the hyperbolization parameter, since Escalante et al. use a reference water height h_0 (and the exact value of the bathymetry b can be changed arbitrarily by moving everything in the vertical direction).

H0 should also not be used since it is a reference for the surface elevation h + b, correct? Maybe we need to introduce another argument, h0, although this can be confusing...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to use H0 - b0 for the reference water height?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - but b0 is not used otherwise. Thus, it would be more straightforward to use another parameter name for it, wouldn't it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes if b0 is not used otherwise I agree it makes more sense to use another parameter name.

Copy link
Copy Markdown
Contributor Author

@MarcoArtiano MarcoArtiano Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using something like h_ref or eta0?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with h_ref and h_0. The docstring is talking about h_0. So why not that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in favor of h_ref because with h_0 I would expect the relation H_0 = b + h_0 to hold.

Comment on lines +152 to +161
"""
flux_conservative_ec(u_ll, u_rr, normal_direction::AbstractVector, equations::HyperbolicSainteMarieEquations1D)

Total energy conserving and well-balanced two-point flux by
- Marco Artiano, Hendrik Ranocha (2026)
On Affordable High-Order Entropy-Conservative/Stable and
Well-Balanced Methods for Nonconservative Hyperbolic Systems
[DOI: 10.48550/arXiv.2603.18978](https://arxiv.org/abs/2603.18978)
"""
struct flux_conservative_ec{RealT <: Real}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Structs should have capital names like FluxConservativeEC. Please also adapt the docstring to describe what the parameters alpha1, alpha2, alpha3 mean, and how the flux can be applied.
It would also be possible to just pick one set of parameters that performs well and stick with it instead of implementing the whole family. I don't have a strong opinion on this. Since performance is not critical right now, it is definitely nice to have the flexibility - but we may recommend some reasonable default value.

Copy link
Copy Markdown
Contributor Author

@MarcoArtiano MarcoArtiano Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the structs' name and adapted the docstrings. We may recommend alpha_1 = 1.0, alpha_2 = 0, alpha_3 = 0, which corresponds to the split form of the shallow water terms and strong form of the remaining terms. Eventually also alpha_1 = 1.0, alpha_2 = 1.0, alpha_3 = 1.0 works (as informative example), which results in a split form for all the terms.

Comment on lines +313 to +328
# Convert conservative variables to entropy
# Note, only the first two are the entropy variables, the third entry still
# just carries the bottom topography values for convenience
@inline function Trixi.cons2entropy(u, equations::HyperbolicSainteMarieEquations1D)
h, h_v, h_w, h_p, b = u

v = h_v / h
w = h_w / h
p = h_p / h

w1 = equations.gravity * (h + b) - 0.5f0 * (v^2 + w^2 + p^2 / equations.celerity^2)
w2 = v
w3 = w
w4 = p / equations.celerity^2
return SVector(w1, w2, w3, w4, zero(eltype(u)))
end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment about the bottom topography and the code do not match.

MarcoArtiano and others added 4 commits March 29, 2026 18:11
Co-authored-by: Hendrik Ranocha <ranocha@users.noreply.github.com>
…work/TrixiShallowWater.jl into ma/hyperbolized_sainte_marie
Copy link
Copy Markdown
Member

@JoshuaLampert JoshuaLampert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good to me. It might make sense to also implement a flux function computing the analytical flux because it enables using, e.g., LLF.

if threshold_limiter === nothing
threshold_limiter = 500 * eps(T)
end
celerity = alpha * sqrt(gravity * b0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we only need the squared celerity it probably makes sense to also just store the square.

Comment on lines +69 to +76
function HyperbolicSainteMarieEquations1D(; gravity, H0 = zero(gravity),
b0 = one(gravity), alpha = 3,
threshold_limiter = nothing)
T = promote_type(typeof(gravity), typeof(H0), typeof(b0), typeof(alpha))
if threshold_limiter === nothing
threshold_limiter = 500 * eps(T)
end
celerity = alpha * sqrt(gravity * b0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with h_ref and h_0. The docstring is talking about h_0. So why not that?

Copy link
Copy Markdown
Member

@patrickersing patrickersing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this new system! That is a really nice addition to the package.
The implementation looks quite good already, I mainly had suggestions about naming conventions and comments.

Could you please also:

Comment on lines +6 to +7
# semidiscretization of the shallow water equations with a discontinuous
# bottom topography function for a fully wet configuration
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# semidiscretization of the shallow water equations with a discontinuous
# bottom topography function for a fully wet configuration
# semidiscretization of the hyperbolic sainte-marie equations for a smooth and periodic initial condition to test entropy conservation


alive_callback = AliveCallback(analysis_interval = analysis_interval)

stepsize_callback = StepsizeCallback(cfl = 0.1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stepsize callback is defined but not included in the CallbackSet.

The additional quantity ``H_0`` is also available to store a reference value for the total water height that
is useful to set initial conditions or test the "lake-at-rest" well-balancedness.
Escalante, Dumbser and Castro (2019) choose the hyperbolization parameter as ``c = \alpha \sqrt{g h_0}`` for some background water height ``h_0``.
Thus, the hyperbolization parameter ``c^2`` is set by the keyword arguments `alpha` (``\alpha``), `gravity` (``g``), and `h0` (``h_0``).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a reminder to make the variable name h_0 consistent to the function argument once we settled on a name.

Comment on lines +69 to +76
function HyperbolicSainteMarieEquations1D(; gravity, H0 = zero(gravity),
b0 = one(gravity), alpha = 3,
threshold_limiter = nothing)
T = promote_type(typeof(gravity), typeof(H0), typeof(b0), typeof(alpha))
if threshold_limiter === nothing
threshold_limiter = 500 * eps(T)
end
celerity = alpha * sqrt(gravity * b0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in favor of h_ref because with h_0 I would expect the relation H_0 = b + h_0 to hold.

gravity::RealT
H0::RealT
celerity::RealT
threshold_limiter::RealT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there is not wet/dry functionality implemented, you can remove threshold_limiter for the equation.

Comment on lines +131 to +132
@inline function source_term_hyperbolic_sainte_marie(u, x, t,
equations::HyperbolicSainteMarieEquations1D)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a docstring to explain the usage of this source term.
This is not optional, but a fundamental part of the equations right?

end

"""
FluxConservativeEC(alpha_1, alpha_2, alpha_3)(u_ll, u_rr, normal_direction::AbstractVector, equations::HyperbolicSainteMarieEquations1D)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name FluxConservativeEC is kept very general. I would prefer to stick with the standard naming convention and name it FluxArtianoEtal and FluxNonconservativeArtianoEtal.

We also use alpha when we determine the hyperbolization parameter. What do you think about changing one of the parameter names to beta to differ between them?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, alpha_i was used in the paper. Thus, we would at least have to describe this difference from the paper.
Moreover, alpha is already used in several places, e.g., for the shock-capturing parameter. However, I do not have a very strong opinion on this; it's your decision what you would like to have in TrixiShallowWater.jl.

In the formal limit ``c^2 \to \infty``, the hyperbolic approximation recovers the original Sainte-Marie system.
The additional quantity ``H_0`` is also available to store a reference value for the total water height that
is useful to set initial conditions or test the "lake-at-rest" well-balancedness.
Escalante, Dumbser and Castro (2019) choose the hyperbolization parameter as ``c = \alpha \sqrt{g h_0}`` for some background water height ``h_0``.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to name this c_ref or c_hyp as we use the variable c already, when we compute the wave celerity in max_abs_speeds.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c_ref sounds good and would be in accordance with h_ref 👍

end

# Helper function to extract the velocity vector from the conservative variables
@inline function Trixi.velocity(u, equations::HyperbolicSainteMarieEquations1D)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also extract the vertical velocity?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not do so. Right now, the velocity dimension is in accordance with the spatial dimensions of the equations. Moreover, the equations do not really model transport in the vertical direction (just resulting vertical velocity coming from the background incompressible Euler system).

Comment on lines +354 to +356
H0_wet_dry = max(equations.H0, b + equations.threshold_limiter)

return abs(H0_wet_dry - (h + b))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
H0_wet_dry = max(equations.H0, b + equations.threshold_limiter)
return abs(H0_wet_dry - (h + b))
return abs(equations.H0 - (h + b))

If we don't consider wetting and drying this can be simplified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants